﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>采购到货单</title>
    <!-- 引入jQuery库 -->
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
    <!-- 此处省略原有的样式引用等内容 -->
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            color: #333;
        }

        h2 {
            margin-bottom: 20px;
            color: #444;
        }

        .action-buttons {
            text-align: right;
            margin-bottom: 20px;
        }

            .action-buttons button {
                padding: 8px 15px;
                border: none;
                border-radius: 4px;
                cursor: pointer;
                margin-left: 10px;
                font-size: 14px;
                transition: background-color 0.2s;
            }

        #saveBtn {
            background-color: #007BFF;
            color: white;
        }

            #saveBtn:hover {
                background-color: #0069d9;
            }

        #cancelBtn {
            background-color: #6c757d;
            color: white;
        }

            #cancelBtn:hover {
                background-color: #5a6268;
            }

        #auditBtn {
            background-color: #28a745;
            color: white;
        }

            #auditBtn:hover {
                background-color: #218838;
            }

        #reverseAuditBtn {
            background-color: #6c757d;
            color: white;
        }

            #reverseAuditBtn:hover {
                background-color: #5a6268;
            }

        #collapseBtn {
            background-color: #6c757d;
            color: white;
        }

            #collapseBtn:hover {
                background-color: #5a6268;
            }

        .form-section {
            border: 1px solid #ddd;
            padding: 20px;
            border-radius: 4px;
            background-color: #fff;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }

        .form-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 15px;
        }

        .form-field {
            margin-bottom: 15px;
        }

            .form-field label {
                display: block;
                margin-bottom: 5px;
                font-weight: 600;
                color: #555;
            }

            .form-field input,
            .form-field select,
            .form-field textarea {
                width: 100%;
                padding: 8px;
                border: 1px solid #ddd;
                border-radius: 4px;
                font-size: 14px;
            }

                .form-field input:focus,
                .form-field select:focus,
                .form-field textarea:focus {
                    border-color: #007BFF;
                    outline: none;
                    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
                }

            .form-field textarea {
                height: 60px;
                resize: vertical;
            }
    </style>
</head>

<body>
    <h2>采购到货单</h2>
    <div class="action-buttons">
        <button id="saveBtn">保存</button>
        <button id="Btn" class="save-button">采购到货明细</button>
        <button id="cancelBtn">取消</button>
        @* <button id="auditBtn">审核</button> *@
        @* <button id="reverseAuditBtn">反审核</button> *@
        <button id="collapseBtn">收起</button>
    </div>
    <div class="form-section">
        <div class="form-grid">
            <!-- 单据编码 -->
            <div class="form-field">
                <label for="documentCode">单据编码:</label>
                <input type="text" id="documentCode" name="documentCode" placeholder="自动生成">
            </div>
            <!-- 业务类型 -->
            <div class="form-field">
                <label class="layui-form-label">业务类型</label>
                <div class="layui-input-block">
                    <select id="documentid" name="documentid" class="layui-select">
                        <option value="0">--请选择部门--</option>
                    </select>
                </div>
            </div>
            <!-- 采购单号 -->
            <div class="form-field">
                <label for="purchaseOrder">采购单号:</label>
                <input type="text" id="purchaseOrder" name="purchaseOrder" placeholder="请输入采购单号">
            </div>
            <!-- 备注信息 -->
            <div class="form-field">
                <label for="remarksInformation">备注信息:</label>
                <textarea id="remarksInformation" name="remarksInformation" placeholder="请输入备注信息"></textarea>
            </div>
            <!-- 单据日期 -->
            <div class="form-field">
                <label for="documentDate">单据日期:</label>
                <input type="date" id="documentStatus" name="documentStatus">
            </div>
            <!-- 操作员 -->
            <div class="form-field">
                <label for="businessName">操作员:</label>
                <input type="text" id="businessName" name="businessName" placeholder="请输入操作员">
            </div>
            <!-- 供应商 -->
            <div class="form-field">
                <label for="supplier">供应商:</label>
                <input type="text" id="supplier" name="supplier" placeholder="请输入供应商">
            </div>
            <!-- 单据状态 -->
            <div class="form-field">
                <label for="bocumentStatus">单据状态:</label>
                <input type="text" id="bocumentStatus" name="bocumentStatus" value="开立" placeholder="请输入操作员">
                <!-- 可添加更多单据状态选项 -->
            </div>
            <!-- 审核员 -->
            <div class="form-field">
                <label for="auditor">审核员:</label>
                <input type="text" id="purchasingDe" name="purchasingDe" placeholder="请输入审核员">
            </div>
            <!-- 入库仓库 -->
            <div class="form-field">
                <label for="warehouse">入库仓库:</label>
                <select id="warehouse" name="warehouse">
                    <option value="">--请选择--</option>
                    <option value="原料仓">原料仓</option>
                    <!-- 可添加具体仓库选项 -->
                </select>
            </div>
            <!-- 业务状态 -->
            <div class="form-field">
                <label for="businessStatus">业务状态:</label>
                <select id="businessStatus" name="businessStatus">
                    <option value="">--请选择--</option>
                    <option value="正常">正常</option>
                    <option value="挂起">挂起</option>
                    <option value="手工关闭">手工关闭</option>
                    <option value="系统关闭">系统关闭</option>
                    <!-- 可添加更多业务状态选项 -->
                </select>
            </div>
            <!-- 审核日期 -->
            <div class="form-field">
                <label for="purchasingTiem">审核日期:</label>
                <input type="date" id="purchasingTiem" name="purchasingTiem">
            </div>
            <!-- 进度情况 -->
            <div class="form-field">
                <label for="progressStatus">进度情况:</label>
                <select id="progressStatus" name="progressStatus">
                    <option value="">--请选择--</option>
                    <option value="进度正常">进度正常</option>
                    <option value="一般延迟">一般延迟</option>
                    <option value="一般超时">一般超时</option>
                    <option value="严重延迟">严重延迟</option>
                    <option value="严重超前">严重超前</option>
                    <!-- 可添加更多进度情况选项 -->
                </select>
            </div>
        </div>
    </div>
    <script>


               // 绑定采购明细按钮点击事件
            $('#Btn').on('click', function () {
                // 替换为实际的跳转 URL
                window.location.href = 'http://localhost:5223/Procurements/matinPurchaseArrival';
                // window.location.href = 'http:localhost:8056/Procurements/matinPurchaseArrival';
            });


             $(document).ready(function () {
            // 获取保存按钮并绑定点击事件
            $('#saveBtn').click(function () {
                // 构建要发送的数据对象
                var formData = {
                    purchaseArrivaId: 0,//采购到货单id
                    documentCode:"",//单据编码
                    documentStatus: $('#documentDate').val(), // 单据日期
                    businessStatus: $('#businessStatus').val(),//业务状态
                    documentid: $('#documentid').val(),//业务类型
                    businessName: $('#businessName').val(),//操作员
                    purchasingDe: $('#purchasingDe').val(),//审核员
                    purchasingTiem: $('#purchasingTiem').val(),//审核日期
                    purchaseOrder: $('#purchaseOrder').val(),//采购单号
                    bocumentStatus:$("#bocumentStatus").val(),
                    supplier: $('#supplier').val(),//供应商
                    warehouse: $('#warehouse').val(),//入库仓库
                    progressStatus: $('#progressStatus').val(),//进度情况
                    remarksInformation: $('#remarksInformation').val()//备注信息
                };

                // 发送AJAX请求
                $.ajax({
                    //url: 'http://localhost:5090/api/PurchaseInvoices/AddPurchaseArrivalder',
                    url: "@ViewBag.BaseUrl/T8/PurchaseInvoices/AddPurchaseArrivalder",
                    type: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify(formData),
                    success: function (res) {
                        if (res.code === 212) {
                            alert('保存成功');
                              window.location.href = "/Procurements/GetPurchaseArrival";
                        } else {
                            alert('保存失败: ' + res.message);
                        }
                    },
                    error: function (xhr, status, error) {
                        alert('保存出错: ' + error);
                    },
                    complete: function () {
                        $('#saveBtn').prop('disabled', false).text('保存');
                    }
                });
            });

            $.ajax({
                //url: "http://localhost:5234/api/Procurements/GetDocument",
                url: "@ViewBag.BaseUrl/T7/Procurements/GetDocument",
                type: "GET",
                success: function (res) {
                    if (res.code === 210) {
                        var options = '<option value="0">--请选择业务类型--</option>';
                        res.data.forEach(item => {
                            options += `<option value="${item.documentid}">${item.documentidName}</option>`;
                        });
                        $('#documentid').html(options);
                    }
                },
                error: function (xhr, status, error) {
                    console.error("加载业务类型失败:", error);
                }
            });
        });


    </script>
</body>

</html>